import { Button } from 'antd';
import type { FC } from 'react';
import { downLoadGoods } from '@/services/coupon.service';
import styles from './index.less';

type TProps = {
  onChange?: TAnyFunction;
  value?: any;
  left?: number;
};

const CommonGoodImport: FC<TProps> = (props) => {
  const { left = 6, onChange } = props;

  const handleImport = () => {
    // console.log('点击导入');
  };

  const handleExport = async () => {
    // console.log('点击导出');
    try {
      const res: any = await downLoadGoods({});
      // console.log('ressss', res.type);
      const url = window.URL.createObjectURL(res);
      const link = document.createElement('a');
      link.style.display = 'none';
      link.download = '商品清单模板'; // 下载的文件名称
      link.href = url;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    } catch (error) {}
  };

  return (
    <div className={styles.pickerShowContainer} style={{ paddingLeft: `${left}em` }}>
      <div style={{ display: 'flex', alignItems: 'center' }}>
        <div style={{ flex: 1, marginRight: '16px' }} className={styles.pickerShowBox}>
          <span className={styles.choseBtn} onClick={handleImport}>
            点击导入
          </span>
        </div>
        <Button type="primary" onClick={handleExport}>
          下载模版
        </Button>
      </div>
    </div>
  );
};

export default CommonGoodImport;
